#include "Frm05.h"

Frm05::Frm05(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm05::~Frm05() {
}

void Frm05::onInit() {

}

void Frm05::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- MButton : wMMButton1                 -----------------------------*/
	wMMButton1 = new STTButton(p_rt, this, "wMMButton1", 1);
	wMMButton1->setMainArg(0, 0, 93, 97, false);
	wMMButton1->setImg("1", "./images/arrow_34_93X97.gray.svg", "");
	wMMButton1->setImg("0", "./images/arrow_34_93X97.svg", "");
	wMMButton1->bindOpenFormHandler(Event::CLICKED, "Frm01", PageMode::NEWWIN, NULL);

	/*----------------------------- Label : wMLabel1                     -----------------------------*/
	wMLabel1 = new STTLabel(p_rt, this, "wMLabel1");
	wMLabel1->setMainArg(154, 32, 95, 33, "温度校准", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel1->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel1->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- TextNumber : wMTextNumber1           -----------------------------*/
	wMTextNumber1 = new STTTextArea(p_rt, this, "wMTextNumber1");
	wMTextNumber1->setMainArg(254, 33, 133, 31, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber1->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 2, 2, 4, 4, 255);
	wMTextNumber1->setPlaceholderText("输入真实温度")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber1->setFont(0x0, 16, "文泉驿微米黑", 0);

	/*----------------------------- Button : wMButton1                   -----------------------------*/
	wMButton1 = new STTButton(p_rt, this, "wMButton1", 0);
	wMButton1->setMainArg(395, 25, 98, 48, false);
	wMButton1->setPressedArg("校准", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->setReleasedArg("校准", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->onEventHandler(Event::CLICKED, this, (EHandler) &Frm05::wMButton1_clk_cb);

	/*----------------------------- Label : wMLabel2                     -----------------------------*/
	wMLabel2 = new STTLabel(p_rt, this, "wMLabel2");
	wMLabel2->setMainArg(522, 32, 95, 33, "湿度校准", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel2->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel2->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- TextNumber : wMTextNumber2           -----------------------------*/
	wMTextNumber2 = new STTTextArea(p_rt, this, "wMTextNumber2");
	wMTextNumber2->setMainArg(622, 33, 133, 31, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber2->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 2, 2, 4, 4, 255);
	wMTextNumber2->setPlaceholderText("输入真实湿度")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber2->setFont(0x0, 16, "文泉驿微米黑", 0);

	/*----------------------------- Button : wMButton2                   -----------------------------*/
	wMButton2 = new STTButton(p_rt, this, "wMButton2", 0);
	wMButton2->setMainArg(763, 25, 98, 48, false);
	wMButton2->setPressedArg("校准", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->setReleasedArg("校准", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->onEventHandler(Event::CLICKED, this, (EHandler) &Frm05::wMButton2_clk_cb);

	/*----------------------------- Label : wMLabel3                     -----------------------------*/
	wMLabel3 = new STTLabel(p_rt, this, "wMLabel3");
	wMLabel3->setMainArg(285, 10, 72, 24, "", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel3->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel3->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel3->setFormatNumerical(2, false, 1, 0.1, 0.0, 0, false, "", "");
	wMLabel3->bindData(_V("温度"));

	/*----------------------------- Label : wMLabel4                     -----------------------------*/
	wMLabel4 = new STTLabel(p_rt, this, "wMLabel4");
	wMLabel4->setMainArg(653, 10, 72, 24, "", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel4->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel4->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel4->setFormatNumerical(2, false, 1, 0.1, 0.0, 0, false, "", "");
	wMLabel4->bindData(_V("湿度"));

	/*----------------------------- Button : wMButton3                   -----------------------------*/
	wMButton3 = new STTButton(p_rt, this, "wMButton3", 0);
	wMButton3->setMainArg(-2, 553, 98, 48, false);
	wMButton3->setPressedArg("系统设置", 0x0, "文泉驿微米黑", 16, 0);
	wMButton3->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton3->setReleasedArg("系统设置", 0x0, "文泉驿微米黑", 16, 0);
	wMButton3->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton3->opDataObj(Event::CLICKED, nullptr, "0");

	/*called after widget created.*/

	return; //createParts END
}

#include "util/StringUtil.h"

void Frm05::onLoad() {
	string bu = KVUtil::getVal("温度补偿","0");
	int ii = StringUtil::safeStoi(bu);
	wMLabel3->setFormatNumerical(2, false, 1, 0.1, ii/100.0, 0, false, "", "");

	string bu2 = KVUtil::getVal("湿度补偿","0");
	int ii2 = StringUtil::safeStoi(bu2);
	wMLabel4->setFormatNumerical(2, false, 1, 0.1, ii2/100.0, 0, false, "", "");
}

bool Frm05::onClosing() {
	return true;
}

void Frm05::onDispose() {

}
#include "util/StringUtil.h"
void Frm05::wMButton1_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton1（校准）的点击事件*/
	double realtmp = StringUtil::safeStod(wMTextNumber1->getText());
	int v;
	vm->getInt("温度",v);
	double samptmp = v / 10.0;
	double dd = (realtmp - samptmp);
	int ii = dd * 100;
	KVUtil::setVal("温度补偿", to_string(ii));
	wMLabel3->setFormatNumerical(2, false, 1, 0.1, dd, 0, false, "", "");
}

void Frm05::wMButton2_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton2（校准）的点击事件*/
	double realtmp = StringUtil::safeStod(wMTextNumber2->getText());
	int v;
	vm->getInt("湿度",v);
	double samptmp = v / 10.0;
	double dd = (realtmp - samptmp);
	int ii = dd * 100;
	KVUtil::setVal("湿度补偿", to_string(ii));
	wMLabel4->setFormatNumerical(2, false, 1, 0.1, dd, 0, false, "", "");
}


